// src/plugins/webp.js
export const webpPlugin = {
  install(app: any) {
    app.config.globalProperties.$webp = (() => {
      try {
        return document.createElement('canvas').toDataURL('image/webp').indexOf('data:image/webp') === 0
      } catch (e) {
        console.warn('This browser does not support Webp!')
        return false
      }
    })()

    // app.directive('webp', {
    //   mounted(el: any, binding: any, vnode: any) {
    //     if (vnode.tag !== 'img') {
    //       return
    //     }
    //
    //     if (isSupportWebp) {
    //       try {
    //         el.src = binding.value.toString().replace(/(\.jpg|\.png)/g, '.webp')
    //       } catch (e) {
    //         console.error(e)
    //       }
    //       document.querySelector('html').classList.add('webp')
    //     }
    //   },
    // })
  },
}
